<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>编辑文章</title>
    <link rel="stylesheet" type="text/css" href="/layui/css/layui.css">
</head>
<body class="bg">
<div class="layui-container">

    <div class="layui-row" style="margin-top: 10px">
        <!--文章头部-->
        <div class="layui-col-md12">
            <span style="font-size: 15px;">标题</span>
        </div>
        <div class="layui-col-md12">
            <input id="title" class="layui-input" type="input" name="title" placeholder="请在这里输入文章标题" >
        </div>
        <!--文章内容-->
        <div class="layui-col-md12">
            <span style="font-size: 15px;">内容</span>
        </div>

        <div class="layui-col-md12">
                <textarea class="layui-textarea" id="LAY_demo1" style="display: none" placeholder="//在这里输入内容">
                </textarea>
        </div>

        <div class="layui-col-md12">
            <a id="commit-btn" href="#" style="float: right;"
               class=" layui-btn-lg  layui-btn">发表</a>
        </div>

    </div>

</div>

<script src="/layui/layui.js" charset="utf-8"></script>
<script src="/js/jquery-3.5.1.js" charset="utf-8"></script>
<script>
    $(function (){
        layui.use('layedit', function(){
            var layedit = layui.layedit
                ,$ = layui.jquery;

            layedit.set({
                uploadImage: {
                    url: '/article/uploadPhoto' //接口url
                    ,type: 'post' //默认post
                }
            });

            //构建一个默认的编辑器
            var index = layedit.build('LAY_demo1');

            $("#commit-btn").click(function (){
                // alert($("#LAY_demo1").text());
                $.ajax({
                    url: "/article/addArticle",
                    method: "post",
                    data: {
                        "title" : $("#title").val(),
                        "content" : layedit.getContent(index)
                    },
                    success: function (){
                        parent.window.location.reload();
                    }
                })
            })

        });
    })

</script>

</body>
</html>